<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <script th:src="@{/js/jquery-2.1.1.js}"></script>
</head>
<body>

<div style="margin: 50px auto;border: 1px solid #929292;width: 500px;height: 300px">
        用户名：<input type="text" name="username" id="username"><br>
        密码：<input type="password" name="password" id="password"><br>
        <button th:onclick="submit()">登录</button>
</div>

</body>
<script>

    function submit() {
        $.ajax({
            type: "post",
            url: "/login",
            data: {username: $("#username").val(),password: $("#password").val()},
            success: function (res) {
                console.log(res)
                if (res.flag) {
                    window.location.href = "/main"
                }else {
                    alert(res.message)
                }
            }
        })
    }


</script>
</html>